package com.zhangj.alljvm.oom;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName OutOfMemoryErrorTest02
 * @Description
 * @Author zhangjie
 * @Date 2022/3/12 7:58
 * @Version 1.0
 */
public class OutOfMemoryErrorTest02 {
    public static void main(String[] args) {

        //先修改堆大小,方便报错
        int i =0;
        List<String> list = new ArrayList<>();

        try {
            while (true){
                list.add(String.valueOf(i++).intern());
            }
        } catch (Throwable e) {
            e.printStackTrace();  //java.lang.OutOfMemoryError: GC overhead limit exceeded
            System.out.println("i最后值为 = " + i);  //i最后值为 = 145770
            throw e;
        } finally {
        }

    }
}
